﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Globalization;

namespace Calhoon.MarkupParser
{
	public class LiteralNode : HierarchyNode
	{
		private string mText;
		public string Text {
			get {
				return mText;
			}
			set {
				mText = value;
			}
		}

		public LiteralNode(Tag createFrom) {
			LiteralPrimitiveTag literalTag = createFrom as LiteralPrimitiveTag;
			if (literalTag != null) {
				TagName = "_Literal";
				mText = literalTag.Text;
			}
		}

		protected override void Render(int level, System.Text.StringBuilder input) {
			Indent(level, input);
			input.Append(mText.Replace("\n", string.Format(CultureInfo.InvariantCulture, "\n{0}", GetIndentation(level))));
		}

		public override bool Equals(object obj) {
			LiteralNode otherNode = obj as LiteralNode;
			if (obj == null) {
				return false;
			}

			return otherNode.Text == this.Text;
		}

		public override int GetHashCode() {
			return base.GetHashCode() ^ mText.GetHashCode();
		}
	}
}